//
//  THJTools.m
//  THJXHW
//
//  Created by 河南德艺 on 17/3/11.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJTools.h"

@implementation THJTools

+(NSString*)getCurrentDate
{
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSString *DateTime = [formatter stringFromDate:date];
    return DateTime;
}
+ (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}
+(NSString *)timestampSwitchTime:(double)timestamp andFormatter:(NSString *)format{
    
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:format];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:timestamp/ 1000.0];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
    
}

+(NSString*)fenLeiStrWith:(NSString*)string{
    if ([string isEqual:@"锰系"]){
        return @"75308";
    }else if ([string isEqual:@"硅系"]){
        return @"75307";
    }else if ([string isEqual:@"铬系"]){
        return @"75313";
    }else if ([string isEqual:@"稀有金属"]){
        return @"75314";
    }else if ([string isEqual:@"多元合金"]){
        return @"75315";
    }else{
        return @"75316";
    }
}
+(NSString*)guigeWithString:(NSString*)string{
    if ([string isEqual:@"标准块10-70mm"]){
        return @"1";
    }else if ([string isEqual:@"标准块10-50mm"]){
        return @"2";
    }else if ([string isEqual:@"自然块"]){
        return @"3";
    }else if ([string isEqual:@"粒(0.5-1mm)"]){
        return @"4";
    }else if ([string isEqual:@"粒(1-3mm)"]){
        return @"5";
    }else if ([string isEqual:@"粒(3-8mm)"]){
        return @"6";
    }else if ([string isEqual:@"粉"]){
        return @"7";
    }else if ([string isEqual:@"面"]){
        return @"8";
    }else{
        return @"获取失败";
    }
}
+(NSString*)guigeTypeChangeToStrWithType:(NSString*)type{
    if ([type isEqual:@"1"]){
        return @"标准块10-70mm";
    }else if ([type isEqual:@"2"]){
        return @"标准块10-50mm";
    }else if ([type isEqual:@"3"]){
        return @"自然块";
    }else if ([type isEqual:@"4"]){
        return @"粒(0.5-1mm)";
    }else if ([type isEqual:@"5"]){
        return @"粒(1-3mm)";
    }else if ([type isEqual:@"6"]){
        return @"粒(3-8mm)";
    }else if ([type isEqual:@"7"]){
        return @"粉";
    }else if ([type isEqual:@"8"]){
        return @"面";
    }else{
        return @"--";
    }
}
+(NSString*)ContraceGuigeTypeChangeToStrWithType:(NSString*)type{
    if ([type isEqual:@"1"]){
        return @"自然宽";
    }else if ([type isEqual:@"2"]){
        return @"标准块";
    }else if ([type isEqual:@"3"]){
        return @"10-50mm";
    }else if ([type isEqual:@"4"]){
        return @"10-70mm";
    }else{
        return @"10-100mm";
    }
}
+(NSString*)hanshuiTypeWithStr:(NSString*)string{
    if ([string isEqual:@"现金含税"]){
        return @"0";
    }else if ([string isEqual:@"现金不含税"]){
        return @"1";
    }else if ([string isEqual:@"承兑含税"]){
        return @"2";
    }else if ([string isEqual:@"承兑不含税"]){
        return @"3";
    }else{
        return @"获取失败";
    }
}
+(NSString*)getStatusStr:(NSInteger)status{
    switch(status) {
        case 0:
            return @"买家发起订单等待卖家确认价格";
            break;
        case 1:
            return @"卖家已回复价格等待买家回复";
            break;
        case 2:
            return @"买家已签合同等待卖家签合同";
            break;
        case 3:
            return @"双方合同确定等待买家付款";
            break;
        case 4:
            return @"买家已付款，等待卖家发货";
            break;
        case 5:
            return @"卖家已发货，等待买家确认";
            break;
        case 6:
            return @"买家确认收货，交易成功";
            break;
    };
    return nil;
}
+(NSString*)getMobile{
    return  [[NSUserDefaults standardUserDefaults]objectForKey:@"MOBILE"];
}
+(NSString*)getToken{
    return  [[NSUserDefaults standardUserDefaults]objectForKey:@"token"];
}
+(void)signOut{
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"token"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MOBILE"];
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"password"];
}
+(BOOL)isHjbUser{
    return  [[NSUserDefaults standardUserDefaults] boolForKey:@"isHjbUser"];
}
+(void)setHjbUser:(BOOL)hjb{
    [[NSUserDefaults standardUserDefaults] setBool:hjb forKey:@"isHjbUser"];
}
//判断是否含有中文
+(BOOL)IsChinese:(NSString *)str {
    for(int i=0; i< [str length];i++){
        int a = [str characterAtIndex:i];
        if( a > 0x4e00 && a < 0x9fff){
            return YES;
        }
    }
    return NO;
}
//
+(BOOL)IsLogIn{
    if([self getToken].length){
        return YES;
    }else{
        return NO;
    }
}
@end
